package com.kldy8.kldyw.tools;

import android.content.Context;
import android.content.res.Resources;
import android.view.WindowManager;

/**
 * Created by BG on 2016/3/30.
 */
public class ScreenTools
{
    WindowManager wm;
    Context myContext;
    public static ScreenTools screenTools;


    public ScreenTools(Context context)
    {
        this.myContext = context;
    }

    public  static ScreenTools instance(Context context)
    {
        if (context == null)
        {
            return null;
        }
       if (screenTools == null)
       {
           screenTools = new ScreenTools(context);
           screenTools.wm = (WindowManager)screenTools.myContext.getSystemService(Context.WINDOW_SERVICE);

       }
        return  screenTools;
    }

    public int getScreenWidth()
    {
       return wm.getDefaultDisplay().getWidth();
    }

    public int getScreenHeight()
    {
        return wm.getDefaultDisplay().getHeight();
    }

    public static float dip2px(float dipValue)
    {
        final float scale = Resources.getSystem().getDisplayMetrics().density;
        return  (dipValue * scale + 0.5f);
    }
}
